package com.challenge.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateParserT {
    /**
     * Date  String、long convert
     * @param args
     */
    public static void main(String[] args) {

        Date dt =new Date();

        //2016-7-6
        String formatDate = null;
        formatDate = DateFormat.getDateInstance().format(dt);
        System.out.println(formatDate);

        //2016-07-06 09:39:58
        DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        formatDate = dFormat.format(dt);
        System.out.println(formatDate);

        //2016-07-06 09:42:44
        DateFormat dFormat12 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        formatDate = dFormat12.format(dt);
        System.out.println(formatDate);

        //2016-07-06 09:39:58
        DateFormat dFormat_ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        formatDate = dFormat_ss.format(dt);
        System.out.println(formatDate);

        //20160706094533
        DateFormat dFormat3 = new SimpleDateFormat("yyyyMMddHHmmss");
        formatDate = dFormat3.format(dt);
        System.out.println(formatDate);

        //1467770970
        long lTime = dt.getTime() / 1000;
        System.out.println(lTime);

        //1464710394 -> ltime2*1000 -> 2016-05-31 23:59:54
        long ltime2 = 1464710394;
        SimpleDateFormat lsdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date lDate = new Date(ltime2*1000);
        String lStrDate = lsdFormat.format(lDate);
        System.out.println(lStrDate);

        //2016-07-06 10:17:48 -> Wed Jul 06 10:17:48 CST 2016
        String strDate = "2016-07-06 10:17:48";
        SimpleDateFormat lsdStrFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date strD = lsdStrFormat.parse(strDate);
            System.out.println(strD);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
